package cn.zxf.note.note.parse;

import cn.zxf.note.BaseAppTest4;
import cn.zxf.note.common.constant.UserConstant;
import cn.zxf.note.note.note.NoteSupport;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.stream.Collectors;

/**
 * Created by zengxf on 2019/7/23.
 */
@Slf4j
public class SaveAndParseDayNote extends BaseAppTest4 {

    @Autowired
    NoteSupport support;

    @Test
    public void parseAndSave() throws IOException {
        String file = "C:\\Users\\Administrator\\Desktop\\aa\\month-note\\test-day.md";
        DayNoteVo day = ParseDayNote.of(file).parse();
        log.info("day: {}", day.getDay());
        log.info("notes-total-size: {}", day.getNotes().size());
        log.info("--------------");
        log.info("--------------");
        day.getNotes().stream()
                .collect(Collectors.groupingBy(NoteVo::getType, LinkedHashMap::new, Collectors.toList()))
                .forEach((type, notes) -> {
                    log.info("type: {}", type);
                    log.info("--------------");
                    notes.forEach(note ->
                            support.saveForImport(UserConstant.DATA_USER, day.getDay(), note)
                    );
                });
    }

}